//
//  CompanyDetailViewController.m
//  CarTown
//
//  Created by xionghao on 15/8/6.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "CompanyDetailViewController.h"
#import "PersonalDetailHeaderTableViewCell.h"
#import "BasicMode.h"
#import "BasicInfoHeaderTableViewCell.h"
#import "OtherHeaderTableViewCell.h"
#import "CarTableCellTableViewCell.h"
#import "SellTableViewController.h"
#import "YeWuTableViewCell.h"
#import "BasicPhoneTableViewCell.h"
#import "BasicPhotoTableViewCell.h"
#import "UMSocial.h"
#import "ShareView.h"
#import "ShareWithBackView.h"
#import "ShopUserItem.h"
#import "ShopHeaderModel.h"
#import "YewuCellMode.h"
#import "ShopTitleModel.h"
#import "CarlistCellMode.h"
#import "CarDetailViewController.h"
#import "Puser.h"
#import "UMSocial.h"
#import "ShareMode.h"
#import "Address.h"
#import "MessageDetailTableViewController.h"
#import "YeWuTableViewController.h"
@interface CompanyDetailViewController ()<UITableViewDelegate,UITableViewDataSource,otherTableCellClickDelegate,ShareclickDelegate,ShareWithBackToIndexDelegate,UIAlertViewDelegate>
{
    CGFloat srcolly;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *BasicAarray;
@property (nonatomic,strong) NSMutableArray *otherAarray;
@property (nonatomic,strong) NSMutableArray *dataarray;
@property (weak, nonatomic) IBOutlet UIButton *attenbtn;
@property (nonatomic,strong) ShopUserItem *item;
@property (nonatomic,strong) Puser *user;
@property (weak, nonatomic) IBOutlet UIToolbar *toolbar;
@end

@implementation CompanyDetailViewController

+(instancetype)viewcontroller{
    CompanyDetailViewController *vc=[XHMianStory instantiateViewControllerWithIdentifier:@"cdvc"];
    return vc;
}
-(NSMutableArray *)dataarray{
    if (_dataarray==nil) {
        _dataarray=[NSMutableArray array];
    }
    return _dataarray;
}
-(NSMutableArray *)BasicAarray{
    if (_BasicAarray==nil) {
        _BasicAarray=[NSMutableArray array];
    }
    return _BasicAarray;
}
-(NSMutableArray *)otherAarray{
    if (_otherAarray==nil) {
        _otherAarray=[NSMutableArray array];
    }
    return _otherAarray;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [cell setSeparatorInset:UIEdgeInsetsZero];
        
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [cell setLayoutMargins:UIEdgeInsetsZero];
        
    }
    
    
    
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==0) {
        return;
    }else{
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.item.com_ctphone]]];
        
    }
    
}

-(void)buttonclick:(NSInteger)ButtonIndex{
    if (ButtonIndex==0) {
        NSLog(@"回到主页");
        
        [self.navigationController popToRootViewControllerAnimated:YES];
        
        
    }else{
        [self share];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.attenbtn setTitle:@"加关注" forState:UIControlStateNormal];
    [self.attenbtn setTitle:@"已关注" forState:UIControlStateSelected];
    [self setupRightButton];
    
    self.tableView.contentInset=UIEdgeInsetsMake(0, 0, 50, 0);
    [self getdataFromWeb];
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
        
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
        
    }
}
-(void)getdataFromWeb{
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    if ([self.parent_id integerValue]!=0||[self.user_type integerValue]==3) {
        params[@"parent_id"]=self.com_id;
    }else{
        params[@"com_id"]=self.com_id;
    }
    params[@"action"]=@"info";
    params[@"car_num"]=@"3";
    int power=[self.user.power intValue];
    if (power<5) {
        params[@"self_id"]=self.user.user_id;
        params[@"type"]=@"0";
        [self animationView:self.toolbar];
    }else{
        
        if (power ==8) {
            params[@"self_id"]=self.user.parent_id;
            params[@"type"]=@"2";
            if ([self.user.parent_id integerValue]!=[self.com_id integerValue]) {
                [self animationView:self.toolbar];
            }
        }else{
            params[@"type"]=@"1";
            params[@"self_id"]=self.user.com_id;
            if ([self.user.com_id integerValue]!=[self.com_id integerValue]) {
                [self animationView:self.toolbar];
            }
        }
    }
    [PostUitls Post:lookforcar parameters:params success:^(id response) {
        
        NSDictionary *dict=response;
        NSNumber *state=dict[@"state"];
        
        ShopUserItem *item=[ShopUserItem shopwithDict:dict[@"data"]];
        self.item=item;
        [self setupData];
        
        
    } failure:^(NSError *error) {
        
    }];
    
}

-(void)shareclickWithIndex:(NSInteger)index{
    [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeWeb;
    UIImage  *shareimg;
    UMSocialUrlResource *resource;
    if ([self.item.shop_logo isEqualToString:@""]||self.item.shop_logo==nil) {
        shareimg=[UIImage imageNamed:@"logo210"];
    }else{
        resource=[[UMSocialUrlResource alloc]initWithSnsResourceType:UMSocialUrlResourceTypeImage url:[NSString getImageURLstr:self.item.shop_logo]];
    }
    
    
    NSDate *nowdate=[NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *str=[dateFormatter stringFromDate:nowdate];
    
    NSString *title=[NSString stringWithFormat:@"%@%@的可售车源【车镇】",self.item.com_name,str];
    NSString *url=[NSString stringWithFormat:@"%@/modules.php?app=cinfo&shop_id=%@",websitehosturl,self.com_id];
    NSString *content=[self.item.com_intro isEqualToString:@""]||self.item.com_intro==nil?DefalutInfostring:self.item.com_intro;
    
    switch (index) {
        case 0:
        {
            
            
            [UMSocialData defaultData].extConfig.wechatSessionData.title =title;
            [UMSocialData defaultData].extConfig.wechatSessionData.url=url;
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:content image:shareimg location:nil urlResource:resource presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    NSLog(@"分享成功！");
                }
            }];
        }
            break;
        case 1:
        {
            
            
            [UMSocialData defaultData].extConfig.wechatTimelineData.title =title;
            [UMSocialData defaultData].extConfig.wechatTimelineData.url=url;
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:content image:shareimg location:nil urlResource:resource presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    NSLog(@"分享成功！");
                }
            }];
        }
            break;
            
        case 2:
        {
            
            
            
        }
            break;
            
        default:
            break;
    }
    
    
    
}
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
-(void)share{
    NSArray *titlearray=@[@"微信",@"朋友圈",@"短信"];
    UIImage *weixin=[UIImage imageNamed:@"weixin"];
    UIImage *pengyou=[UIImage imageNamed:@"liulan"];
    UIImage *sms=[UIImage imageNamed:@"duanxin"];
    NSArray *icon=@[weixin,pengyou,sms];
    ShareView *share=[[ShareView alloc]initWithTitle:titlearray andIcons:icon delegate:self];
    [share show];
}
-(void)setupData{
    if ([self.item.atten integerValue]==0) {
        self.attenbtn.selected=NO;
    }else{
        self.attenbtn.selected=YES;
    }
    ShopHeaderModel *mode=[[ShopHeaderModel alloc]init];
    mode.headname=self.item.com_name;
    mode.headpic=self.item.shop_logo;
    mode.shoptype=self.item.shop_cat_name;
    
    [self.dataarray addObject:@[mode]];
    
    BasicMode *suozaidi=[[BasicMode alloc]init];
    suozaidi.name=@"所在区域";
    //    suozaidi.detail
    //    Address *pro=[Address getAdressbyID:self.item.shop_];
    //    Address *city=[Address getAdressbyID:self.item.user_city];
    //    Address *dist=[Address getAdressbyID:self.item.user_district];
    if ([self.item.province isEqualToString:self.item.city]) {
        suozaidi.detail=[NSString stringWithFormat:@"%@%@",self.item.city,self.item.district];
        if ([self.item.city isEqualToString:self.item.district]) {
            suozaidi.detail=[NSString stringWithFormat:@"%@",self.item.district];
        }
    }else{
        suozaidi.detail=[NSString stringWithFormat:@"%@%@%@",self.item.province,self.item.city,self.item.district];
    }
    [self.BasicAarray addObject:suozaidi];
    BasicMode *dizhi=[[BasicMode alloc]init];
    dizhi.name=@"详细地址";
    dizhi.detail=[self.item.com_adress isEqualToString:@""]?@"暂无":self.item.com_adress;
    dizhi.ismultlesLines=[self.item.com_adress isEqualToString:@""]?NO:YES;
    [self.BasicAarray addObject:dizhi];
    BasicMode *personinfo=[[BasicMode alloc]init];
    personinfo.name=@"门头照片";
    personinfo.detail=@"暂无";
    personinfo.isNUll=self.item.shop_men_imgs.count>0?NO:YES;
    personinfo.imgsarray=self.item.shop_men_imgs;
    personinfo.isImageMode=YES;
    [self.BasicAarray addObject:personinfo];
    BasicMode *jianyie=[[BasicMode alloc]init];
    jianyie.name=@"商铺简介";
    jianyie.detail=[self.item.com_intro isEqualToString:@""]||self.item.com_intro==nil?@"暂无":self.item.com_intro;
    jianyie.isImageMode=NO;
    jianyie.ismultlesLines=[self.item.com_intro isEqualToString:@""]?NO:YES;;
    [self.BasicAarray addObject:jianyie];
    BasicMode *phone1=[[BasicMode alloc]init];
    phone1.name=self.item.com_ctusername;
    phone1.detail=[self.item.com_ctphone isEqualToString:@""]||self.item.com_ctphone==nil?@"暂无":self.item.com_ctphone;
    phone1.isImageMode=NO;
    phone1.isPhone=YES;
    phone1.blcok=^{
        if ([self.item.com_ctphone isEqualToString:@""]) {
            return;
        }
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tell://%@",self.item.com_ctphone]]];
    };
    [self.BasicAarray addObject:phone1];
    
    if (![self.item.com_qq isEqualToString:@""]&&self.item.com_qq) {
        BasicMode *qq=[[BasicMode alloc]init];
        qq.name=@"QQ";
        qq.detail=self.item.com_qq;
        [self.BasicAarray addObject:qq];
    }
    
    if (![self.item.com_weixin isEqualToString:@""]&&self.item.com_weixin) {
        BasicMode *weichat=[[BasicMode alloc]init];
        weichat.name=@"微信";
        weichat.detail=self.item.com_weixin;
        [self.BasicAarray addObject:weichat];
    }
    
    if (self.item.son_u.count>0) {
        YewuCellMode *yewu=[[YewuCellMode alloc]init];
        yewu.blcok=^{
            YeWuTableViewController *vc=[YeWuTableViewController viewController];
            vc.conarray=self.item.son_u;
            [self.navigationController pushViewController:vc animated:YES];
        };
        [self.BasicAarray addObject:yewu];
    }
    [self.dataarray addObject:self.BasicAarray];
    CarlistCellMode *titlemode=[[CarlistCellMode alloc]init];
    [self.otherAarray addObject:titlemode];
    for (CarDetailmodel *cardetail in self.item.my_car) {
        CarlistCellMode *carcell=[[CarlistCellMode alloc]init];
        carcell.cardmode=cardetail;
        [self.otherAarray addObject:carcell];
    }
    [self.dataarray addObject:self.otherAarray];
    [self.tableView reloadData];
    
}




-(void)setupRightButton{
    ShareWithBackView *shareandback=[ShareWithBackView sharewithback];
    shareandback.delegate=self;
    UIBarButtonItem *rightitem=[[UIBarButtonItem alloc] initWithCustomView:shareandback];
    self.navigationItem.rightBarButtonItem=rightitem;
    self.automaticallyAdjustsScrollViewInsets=NO;
}
-(void)setupNav:(BOOL)isTOP{
    if (isTOP) {
        UIImage *clearimage= [UIImage imageNamed:@"v_line"];
        [self.navigationController.navigationBar setBackgroundImage:clearimage forBarMetrics:UIBarMetricsDefault];
        [self.navigationController.navigationBar setTranslucent:YES];
        [self.navigationController.navigationBar setShadowImage:clearimage];
        [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    }else{
        UIImage *detail= [UIImage imageNamed:@"detail_navbg"];
        [self.navigationController.navigationBar setBackgroundImage:detail forBarMetrics:UIBarMetricsDefault];
        [self.navigationController.navigationBar setTranslucent:YES];
        
        [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
        
    }
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setupSollNav:srcolly];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGPoint offset = scrollView.contentOffset;
    float y = offset.y;
    srcolly=y;
    [self setupSollNav:y];
    
}
-(void)setupSollNav:(CGFloat )y{
    
    float reload_distance = -20;
    
    if(y > 91 + reload_distance) {
        //距离到底 20 像素
        NSLog(@"改变状态栏颜色");
        
        [self setupNav:NO];
    }else{
        [self setupNav:YES];
    }
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 0.1;
    }else{
        return 30;
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, XHScreenheight, 30)];
    view.backgroundColor=UIColorWithRGB(238, 238, 238);
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(16, 0, XHScreenheight, 30)];
    [view addSubview:lable];
    lable.font=[UIFont systemFontOfSize:14];
    lable.textColor=textnormalGary;
    
    if (section==0) {
        view.height=0;
    }else if (section==1){
        lable.text=@"基本信息";
        view.height=30;
    }else{
        if ([self.parent_id integerValue]!=0||[self.user_type integerValue]==3) {
             lable.text=@"该业务员其他车源";
        }else{
        lable.text=@"商家其他车源";
        }
        view.height=30;
    }
    return view;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataarray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSArray *array=self.dataarray[section];
    return array.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array=self.dataarray[indexPath.section];
    if (indexPath.section !=2) {
        
        BasicMode *mode=array[indexPath.row];
        if ([mode isKindOfClass:[ShopHeaderModel class]]) {
            PersonalDetailHeaderTableViewCell *cell=[PersonalDetailHeaderTableViewCell cellWithTable:tableView];
            cell.headermode=mode;
            return cell;
        }else if ([mode isKindOfClass:[YewuCellMode class]]){
            YeWuTableViewCell *cell=[YeWuTableViewCell cellWithTableView:tableView];
            return cell;
        }else if (mode.isPhone){
            BasicPhoneTableViewCell *cell=[ BasicPhoneTableViewCell cellWithTableView:tableView];
            cell.titlelable.text=mode.name;
            cell.phonenumber.text=mode.detail;
            return cell;
        }
        else if(mode.isImageMode&&!mode.isNUll)
        {
            BasicPhotoTableViewCell *cell=[BasicPhotoTableViewCell cellWithTableView:tableView];
            cell.imgarray=mode.imgsarray;
            return cell;
        }else
        {
            UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"basiccell"];
            if (cell==nil) {
                cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"basiccell"];
                cell.textLabel.textColor=UIColorWithRGB(178, 178, 178);
                if (mode.isNUll) {
                    cell.detailTextLabel.textColor=placehodlerColor;
                    
                }else{
                    cell.detailTextLabel.textColor=UIColorWithRGB(112, 112, 112);
                }
                
            }
            if (mode.ismultlesLines) {
                cell.detailTextLabel.numberOfLines=0;
            }
            cell.textLabel.font=[UIFont systemFontOfSize:15];
            cell.textLabel.text=mode.name;
            cell.detailTextLabel.text=mode.detail;
            cell.detailTextLabel.font=[UIFont systemFontOfSize:13];
            return cell;
        }
        
    } else{
        CarlistCellMode *cellmode=array[indexPath.row];
        if (indexPath.row==0) {
            OtherHeaderTableViewCell *cell=[OtherHeaderTableViewCell cellWithTableView:tableView];
            cell.tableclickdelegate=self;
            return cell;
        }else{
            CarTableCellTableViewCell *cell=[CarTableCellTableViewCell cellWithTableView:tableView];
            cellmode.cardmode.shop_name=self.item.com_name;
            cell.carcellmode=cellmode;
            return cell;
        }
    }
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array=self.dataarray[indexPath.section];
    if (indexPath.section!=2) {
        BasicMode *mode=array[indexPath.row];
        if (mode.blcok) {
            mode.blcok();
        }
    }else{
        CarlistCellMode *cellmode=array[indexPath.row];
        if (indexPath.row==0) {
            return;
        }
        CarDetailViewController *vc=[CarDetailViewController viewcontroller];
        vc.ID=cellmode.cardmode.ID;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

-(void)click:(NSInteger)tag{
    NSLog(@"%ld",tag);
    if (tag==0) {
        
        UIImage  *shareimg;
        UMSocialUrlResource *resource;
        if ([self.item.shop_logo isEqualToString:@""]||self.item.shop_logo==nil) {
            shareimg=[UIImage imageNamed:@"logo210"];
        }else{
            resource=[[UMSocialUrlResource alloc]initWithSnsResourceType:UMSocialUrlResourceTypeImage url:[NSString getImageURLstr:self.item.shop_logo]];
        }
        NSDate *nowdate=[NSDate date];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        NSString *str=[dateFormatter stringFromDate:nowdate];
        
        NSString *title=[NSString stringWithFormat:@"%@%@的可售车源【车镇】",self.item.com_name,str];
        
        ShareMode *mode=[[ShareMode alloc]init];
        mode.sharecontent=[self.item.com_intro isEqualToString:@""]||self.item.com_intro==nil?DefalutInfostring:self.item.com_intro;
        mode.sharetitle=title;
        mode.logo=shareimg;
        mode.resource=resource;
        mode.url=[NSString stringWithFormat:@"%@/modules.php?app=sale_car&shop_id=%@&shop_name=%@&sale_attr=1",websitehosturl,self.com_id,self.item.com_name];
        
        SellTableViewController *stvc=[XHMianStory instantiateViewControllerWithIdentifier:@"sell"];
        stvc.sharemode=mode;
        stvc.comid=self.com_id;
        if (self.parent_id==nil) {
            self.parent_id=@"0";
        }
        stvc.parentid=self.parent_id;
        [self.navigationController pushViewController:stvc animated:YES];
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSArray *array=self.dataarray[indexPath.section];
    if (indexPath.section !=2) {
        BasicMode *mode=array[indexPath.row];
        
        if ([mode isKindOfClass:[ShopHeaderModel class]]) {
            return 180;
        }else if (mode.ismultlesLines){
            return mode.rowheight;
        }else if(mode.isImageMode&&!mode.isNUll){
            return 80;
        }else{
            return 44;
        }
        
    }
    else{
        CarlistCellMode *listcell=array[indexPath.row];
        if (listcell.rowheight) {
            return listcell.rowheight;
        }else{
            return 44;
        }
    }
    
}
- (IBAction)bottomclick:(UIButton *)sender {
    
    switch (sender.tag) {
        case 0:
            [self guanzhu:sender];
            break;
        case 1:
            [self sendmessage];
            break;
        case 2:
            [self tellphone];
            break;
        default:
            break;
    }
    
    
}
-(Puser *)user{
    if (_user==nil) {
        _user=[Puser getUser];
    }
    return _user;
}
-(void)animationView:(UIView *)view{
    view.alpha=0.0f;
    view.hidden=NO;
    [UIView animateWithDuration:0.5 delay:0.2 options:UIViewAnimationOptionLayoutSubviews animations:^{
        view.alpha=1.0f;
    } completion:^(BOOL finished) {
        
    }];
}
-(void)guanzhu:(UIButton *)sender{
    
    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
    hud.labelText=@"正在操作";
    hud.margin = 10.f;
    
    hud.removeFromSuperViewOnHide = YES;
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    if (sender.selected) {
        params[@"action"]=@"cansol";
        params[@"shop_id"]=[self.parent_id integerValue]!=0?self.parent_id:self.com_id;
        params[@"type"]=@"1";
        if ([self.user.power integerValue]==1) {
            params[@"user_id"]=self.user.user_id;
        }else{
            if ([self.user.power integerValue]==5) {
                params[@"com_id"]=self.user.com_id;
            }else if ([self.user.power integerValue]==8){
                params[@"parent_id"]=self.user.parent_id;
            }
        }
        
    }else{
        params[@"action"]=@"add_faver";
        params[@"shop_id"]=[self.parent_id integerValue]!=0?self.parent_id:self.com_id;
        params[@"type"]=@"1";
        if ([self.user.power integerValue]==1) {
            params[@"user_id"]=self.user.user_id;
        }else{
            if ([self.user.power integerValue]==5) {
                params[@"com_id"]=self.user.com_id;
            }else if ([self.user.power integerValue]==8){
                params[@"parent_id"]=self.user.parent_id;
            }
        }
    }
    
    [PostUitls Post:addgzurl parameters:params success:^(id response) {
        NSDictionary *dict=response;
        
        hud.mode=MBProgressHUDModeText;
        hud.labelText=dict[@"msg"];
        NSNumber *state=dict[@"state"];
        if ([state integerValue]==400) {
            sender.selected=!sender.selected;
        }
        
        [hud hide:YES afterDelay:1];
        
    } failure:^(NSError *error) {
        hud.mode=MBProgressHUDModeText;
        hud.labelText=@"网络错误";
        
        
        [hud hide:YES afterDelay:1];
    }];
    
    
}
-(void)sendmessage{
    
    for (UIViewController *vc in self.navigationController.viewControllers) {
        if ([vc isKindOfClass:[MessageDetailTableViewController class]]) {
            [self.navigationController popToViewController:vc animated:YES];
            return;
        }
    }
    
    MessageDetailTableViewController *mvc=[[MessageDetailTableViewController alloc]init];
    mvc.toico=self.item.shop_logo;
    mvc.toid=self.com_id;
    if ([self.parent_id integerValue]!=0) {
        mvc.totype=@"3";
        mvc.navigationItem.title=self.item.com_ctusername;
    }else{
        if (self.user_type) {
            mvc.totype=self.user_type;
            if ([self.user_type integerValue]==2) {
                mvc.navigationItem.title=self.item.com_name;
            }else{
                mvc.navigationItem.title=self.item.com_ctusername;
            }
        }
        
    }
    
    [self.navigationController pushViewController:mvc animated:YES];
    
}
-(void)tellphone{
    
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"确定拨打此电话" message:self.item.com_ctphone delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alert show];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
